﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;

namespace Dazaza.Framework.Utility
{
    public class SerializeHelper
    {
        public static void SerializeToXml<T>(T t, string diskPath) where T : class,new()
        {
            FileStream fs = System.IO.File.OpenWrite(diskPath);
            XmlSerializer xs = new XmlSerializer(typeof(T));
            xs.Serialize(fs, t);
            fs.Close();
        }

        public static T DeSerializeXml<T>(string diskPath) where T : class,new()
        {
            FileStream fs = new FileStream(diskPath, FileMode.OpenOrCreate);
            XmlSerializer xs = new XmlSerializer(typeof(T));
            T t = (T)xs.Deserialize(fs);
            fs.Close();
            return t;
        }
    }
}
